/**
 *
 */
package com.iis.hrms.controller;

import com.iis.hrms.service.LoginService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author firdaus
 */
@Controller
public class Login {

    private Logger log = Logger.getLogger(Login.class);

    @Autowired
    private LoginService loginService;

    @RequestMapping("/login.do")
    public ModelAndView login() {
        return new ModelAndView("index");
    }

    @RequestMapping("/validation.do")
    public void validation(HttpServletRequest req, HttpServletResponse res, @RequestParam(value = "username", required = true) String username, @RequestParam(value = "password", required = true) String password) throws IOException {
        log.info("Username = " + username);
        log.info("Password = " + password);
        PrintWriter out = res.getWriter();
        res.setContentType("text/html");
        if (loginService.validation(username, password)) {
            out.print("Username : " + username + " password :" + password);
        } else {
            out.print("gagal login");
        }

    }
}
